<template>
  <div class="app-container">


    <!-- 首页内容 -->
    <div class="page-container-wrap">
      <div class="page-container">
        <div class="recent-posts">
          <div class="announcement background-opacity" :class=" sortPage ?'announcement-max-width':''">
            <i class="fa fa-volume-up" aria-hidden="true"></i>
            <div>
              <div v-for="(notice, index) in notices" :key="index">
                {{route.query.sortId }}
              </div>
            </div>
          </div>
          <model-type></model-type>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import {listArticle,selectArticlesByType} from "@/api/weblog/article";
// import modelType from "@/views/weblogFront/util/modelType.vue"
import modelType from "@/views/weblogFront/videoCatalog/layoutTile.vue"
import {getCurrentInstance, nextTick, onMounted, reactive, ref, shallowRef, watch} from "vue";
import {useRoute, useRouter} from "vue-router";
import {getSort} from "@/api/weblog/sort";
const { proxy } = getCurrentInstance();
const key = ref(1);
const notices = ref(["公告一"]);
const open = ref(false);
const sortPage = ref(false);
const articles = ref([]);
const pagination = ref({
  current: 1,
  size: 10,
  total: 0,
  searchKey: "",
  sortId: null,
  labelId:"",
  articleSearch: ""
})
const route = useRoute();
const router = useRouter();
const modelKey = ref(1);
const articleRows = ref(0);
const articleColumns = ref(0);


const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

async function getArticles() {
  let axiosResponse = await listArticle(pagination.value);
  articles.value = axiosResponse.rows;
  pagination.value.total = axiosResponse.total;
  await nextTick(() => {
    modelKey.value = modelKey.value + 1
  })

}


onMounted(() => {
  // refreshArticle()
})

watch(() => route.query.sortId, (newId, oldId) => {
  // 当路由参数变化时执行的逻辑
  if (newId !== oldId) {
    refreshArticle(newId);
  }
});

const refreshArticle =async () => {

  let response = await getSort(route.query.sortId);
  articleRows.value = response.data.articleRows
  articleColumns.value = response.data.articleColumns

  pagination.value = {
    current: 1,
    size: 10,
    total: 0,
    searchKey: "",
    labelId: route.query.labelId,
    sortId: route.query.sortId,
    articleSearch: ""
  };
  await getArticles();
}

// getList();
</script>
<style scoped>

.toolbar-content {
  width: 100%;
  height: 600px !important;
  /* 固定位置，不随滚动条滚动 */
  position: fixed;
  z-index: 100;
  /* 禁止选中文字 */
  user-select: none;
  transition: all 0.3s ease-in-out;
}



.page-container-wrap {
  background: var(--indexbg);
  position: relative;
  min-height: 100vh;
}

.page-container {
  display: flex;
  justify-content: center;
  width: 90%;
  padding: 60px 20px 40px 20px;
  margin: 0 auto;
  flex-direction: row;
}

.recent-posts {
  width: 70%;
}

.announcement {
  padding: 22px;
  border: 1px dashed var(--lightGray);
  color: var(--greyFont);
  border-radius: 10px;
  display: flex;
  margin: 40px auto 40px;
}

.announcement i {
  color: var(--themeBackground);
  font-size: 22px;
  margin: auto 0;
  animation: scale 0.8s ease-in-out infinite;
}
.announcement-max-width{
  max-width: 780px;
}

.announcement div div {
  margin-left: 20px;
  line-height: 30px;
}

.aside-content {
  width: calc(30% - 40px);
  user-select: none;
  margin-top: 40px;
  margin-right: 40px;
  max-width: 300px;
  float: right;
}

.pagination-wrap {
  display: flex;
  justify-content: center;
  margin-top: 40px;
}

.pagination {
  padding: 13px 15px;
  border: 1px solid var(--lightGray);
  border-radius: 3rem;
  color: var(--greyFont);
  width: 100px;
  user-select: none;
  cursor: pointer;
  text-align: center;
}

.pagination:hover {
  border: 1px solid var(--themeBackground);
  color: var(--themeBackground);
  box-shadow: 0 0 5px var(--themeBackground);
}

@media screen and (max-width: 1100px) {
  .recent-posts {
    width: 100%;
  }

  .page-container {
    width: 100%;
  }
}

@media screen and (max-width: 1000px) {

  .page-container {
    /* 文章栏与侧标栏垂直排列 */
    flex-direction: column;
  }

  .aside-content {
    width: 100%;
    max-width: unset;
    float: unset;
    margin: 40px auto 0;
  }
}

@media screen and (max-width: 768px) {

  h1 {
    font-size: 35px;
  }
}

.app-container {
  padding: 0px !important;
}
</style>
